package org.jsbd.boss.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IUmConfigInfoDao;
import org.jsbd.boss.dao.IUmConfigProvinceDao;
import org.jsbd.boss.domian.UmConfigInfo;
import org.jsbd.boss.domian.UmConfigProvince;
import org.jsbd.boss.service.IUmConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UmConfigInfoServiceImpl implements IUmConfigInfoService {

	@Autowired
	private IUmConfigInfoDao umConfigInfoDao;
	
	@Autowired
	private IUmConfigProvinceDao umConfigProvinceDao;

	@Override
	public void save(UmConfigInfo umConfigInfo) {
		umConfigInfoDao.save(umConfigInfo);
	}

	@Override
	public void save(List<UmConfigInfo> list) {
		umConfigInfoDao.save(list);
	}

	@Override
	public int update(UmConfigInfo umConfigInfo) {
		return umConfigInfoDao.update(umConfigInfo);
	}

	@Override
	public UmConfigInfo getById(Integer id) {
		return umConfigInfoDao.getById(id);
	}

	@Override
	public List<UmConfigInfo> getList(UmConfigInfo umConfigInfo) {
		return umConfigInfoDao.getList(umConfigInfo);
	}

	@Override
	public Map<String, Object> getListPage(DataGridModel page, UmConfigInfo umConfigInfo) {
		umConfigInfo = (umConfigInfo == null ? new UmConfigInfo() : umConfigInfo);
		umConfigInfo.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", umConfigInfoDao.getListPageCount(umConfigInfo));

		List<UmConfigInfo> list = (List<UmConfigInfo>) umConfigInfoDao.getList(umConfigInfo);
		for (UmConfigInfo bk : list) {
			bk.setCreateDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getCreateTime()));
			bk.setModifyDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getModifyTime()));
		}
		results.put("rows", list);
		return results;
	}

	@Override
	public void delete(List<Integer> ids) {
		umConfigInfoDao.delete(ids);
		
		for (Integer id : ids) {
			UmConfigProvince province = new UmConfigProvince();
			province.setConfigInfoId(id);
			umConfigProvinceDao.delete(province);
		}
	}

}
